package com.leetcode.array;

import java.util.Arrays;

/**
 * 这个题不是和344题基本类似，但是他只交换元音
 */
public class Leetcode345 {
    public String reverseVowels(String s) {
        if (s == null || s.length() == 0) {
            return s;
        }
        char[] str = s.toCharArray();
        int left = 0;
        int right = str.length - 1;
        while (left < right) {
            char lChar = str[left];
            if (!isVowel(lChar)) {
                left++;
                continue;
            }
            char rChar = str[right];
            if (!isVowel(rChar)) {
                right--;
                continue;
            }
            char tmp = lChar;
            str[left] = str[right];
            str[right] = tmp;
            left++;
            right--;
        }
        return convertArrToStr(str);
    }

    private String convertArrToStr(char[] s) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < s.length ; i++) {
            str.append(s[i]);
        }
        return str.toString();
    }

    private boolean isVowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
                || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
    }

    public static void main(String[] args) {
        String s = "aA";
        Leetcode345 leet = new Leetcode345();
        String str = leet.reverseVowels(s);
        System.out.println(str);
    }

}
